package com.baizhi.wwk.service;

import com.baizhi.wwk.dao.UserMapper;
import com.baizhi.wwk.entity.User;
import com.baizhi.wwk.entity.UserExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    @Override
    public Map<String, Object> queryAllPage(int page, int pageSize) {
        Map<String ,Object> map=new HashMap<>();
        UserExample userExample = new UserExample();
        RowBounds rowBounds = new RowBounds(0, 3);
        List<User> userList = userMapper.selectByExampleAndRowBounds(userExample, rowBounds);
        int totalCount = userMapper.selectCount(null);
        map.put("total",totalCount);
        map.put("page",page);
        map.put("rows",userList);
        return map;

    }

    @Override
    public Map<String, Object> update(int id,String status) {
        Map<String,Object> map=new HashMap<>();
        User user=new User();
        user.setId(id);
        user.setStatus(status);
        int i = userMapper.updateByPrimaryKeySelective(user);
        if (i==1){
            map.put("message","操作失败");
            map.put("status",200);
        }else {
            map.put("message","操作成功");
            map.put("status",200);
        }
    return map;
    }
}
